<?php
/////////////////////////////////////////////////////////////////////////////
// @author lee99 <lee99.com@gmail.com> Sat Mar 15 11:32:05 GMT 2008
//+----------------------------------------------------------
//说明
//+----------------------------------------------------------
/////////////////////////////////////////////////////////////////////////////


class LabelsAction extends PublicAction{

	
	public function index(){
		$this->display();
	}	
	

	public function ajaxlist(){

		$list=D("Labels");

		$order=!empty($_REQUEST["order"])?$_REQUEST["order"]:$list->getPk(); //排序字段,默认为"Pk"
		$sortd=!empty($_REQUEST["sort"])?$_REQUEST["sort"]:"asc"; //排序顺序,默认为"asc"
		$orderBy=$order." ".$sortd;//组合排序条件

		$feilds='id,pid,title,pageurl,isip,ismap,isad,isbiz,create_on,update_on,id';

        $condition=Array();//搜索的条件
        //$condition['title']=array('like',"a%");//高级搜索过滤

    if(!empty($_REQUEST['searchkey'])){
		//搜索相关
		$searchkey=$_REQUEST["searchkey"];
		$searchtype=!empty($_REQUEST['searchtype'])?$_REQUEST['searchtype']:'OR';//默认的公共搜索条件为OR

		$this->assign("searchkey",$_REQUEST["searchkey"]);//显示关键字
		$this->assign("searchurl",$_SERVER["REQUEST_URI"]);//当前的URL
		$this->assign("searchtype",$_REQUEST["searchtype"]);//当前的搜索类型

        $ser_c=array('like',"%$searchkey%");//公共的过滤条件
        $condition['id,pid,title,pageurl,isip,ismap,isad,isbiz,create_on,update_on,id']=array($ser_c,$ser_c,$ser_c,$ser_c,$ser_c,$ser_c,$ser_c,$ser_c,$ser_c,$ser_c,id,$searchtype);//模糊搜索关键字全局过滤
    }

		
		$count= $list->count($condition);//获取分页总数量
		$p= new ajaxpage($count);
		$page=$p->ajaxshow();//显示分页
		$this->assign("page",$page);//显示分页
		$limit=$p->firstRow.",".$p->listRows;//设定分面的大小

		$limit=($limit==",")?'':$limit;//分页的大小

		$list=$list
			->where($condition)
			->field($feilds)
			->order($orderBy)
			->limit($limit)
			->findAll();

		$this->assign("list",$list);

		$this->display();

	}






	public function insert(){
		$list=D("Labels");
		$data=$_REQUEST;

        /*
		if(!empty($_FILES)) {
          $file= $this->_upload();//如果有文件上传 上传附件
			foreach ($file as $key=>$value){
				$data[$key]=$value['savename'];
			}
        }
        */

        if($list->create($data)) {
            if($list->add($data)){
                $this->success('数据增加成功！');
            }else{
                $this->error('数据增加错误！');
            }
        }else{
             $this->error($list->getError());
        }

	}








	public function update(){
		$list=D("Labels");
		$data=$_REQUEST;

		/*
        if(!empty($_FILES)) {
          $file= $this->_upload();//如果有文件上传 上传附件
			foreach ($file as $key=>$value){
				$data[$key]=$value['savename'];
			}
        }
        */
		
        if($vo = $list->create($data)) {
            if($list->save($data)){
                $this->success('数据更新成功！');
            }else{
                $this->error('数据更新错误！');
            }
        }else{
             $this->error($list->getError());
        }
	}





	public function edit(){
		$result=D("Labels");
		$list=$result->getById($_GET['id']);
		$this->assign('list',$list);
				$this->assign("id",$list["id"]);
		$this->assign("pid",$list["pid"]);
		$this->assign("title",$list["title"]);
		$this->assign("pageurl",$list["pageurl"]);
		$this->assign("isip",$list["isip"]);
		$this->assign("ismap",$list["ismap"]);
		$this->assign("isad",$list["isad"]);
		$this->assign("isbiz",$list["isbiz"]);
		$this->assign("create_on",$list["create_on"]);
		$this->assign("update_on",$list["update_on"]);

		$this->display();
	}




	public function view(){
		$result=D("Labels");
		$list=$result->getById($_GET['id']);
		$this->assign('list',$list);
				$this->assign("id",$list["id"]);
		$this->assign("pid",$list["pid"]);
		$this->assign("title",$list["title"]);
		$this->assign("pageurl",$list["pageurl"]);
		$this->assign("isip",$list["isip"]);
		$this->assign("ismap",$list["ismap"]);
		$this->assign("isad",$list["isad"]);
		$this->assign("isbiz",$list["isbiz"]);
		$this->assign("create_on",$list["create_on"]);
		$this->assign("update_on",$list["update_on"]);

		$this->display();
	}




	public function add(){
		$this->display();
	}



}
?>